<?php
// +----------------------------------------------------------------------
// | najing [ 通用后台管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://www.najingquan.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: lin
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\common\controller\AdminController;
use app\common\model\CarouselSeat as positionModel;
use think\facade\Request;
use think\facade\View;

/**
 * 广告位管理
 * Class CarouselSeat
 * @package app\admin\controller
 */
class CarouselSeat extends AdminController
{

    /**
     *  广告位列表
     * @author lin
     */
    public function index()
    {
        $position = new positionModel();
        if ($this->request->isAjax()) {
            return $position->tableData(input('param.'));
        }
        return View::fetch();
    }


    /**
     *  添加广告位
     * @author lin
     */
    public function add()
    {
        View::layout(false);
        $position = new positionModel();
        if ($this->request->isPost()){
            return $position->addData(input('param.'));
        }
        return [
            'status' => true,
            'msg'    => '获取成功',
            'data'   => View::fetch('add', [
                    'list' => config('carousel_seat.list')
                ]
            )
        ];
    }


    /**
     *  广告位编辑
     * @author lin
     */
    public function edit()
    {
        View::layout(false);
        $positionModel = new positionModel();
        if ($this->request->isPost()){
            return $positionModel->saveData(input('param.'));
        }
        $info = $positionModel->where('id', input('param.id/d'))->find();
        if (!$info) {
            return error_code(10002);
        }

        return [
            'status' => true,
            'msg'    => '获取成功',
            'data'   => View::fetch('', ['info' => $info])
        ];
    }

    /**
     *  广告位删除
     * @author lin
     */
    public function del()
    {
        $position = new positionModel();
        return $position->del(input('param.id/d'));
    }

}